/*

 Copyright (c) 2008-2009 Fabrizio Pistonesi

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 */

#ifndef _NODE_H_
#define _NODE_H_

#include <audiere.h>
using namespace audiere;

#include <irrlicht.h>
#include <vector>
#include "cursor.h"
#include "patch.h"
#include "sound.h"
#include "sensor.h"
//#include "hotspotmap.h"

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

enum ENODE_TYPE
  {
  ENT_SLIDE = 0, ENT_PANEL, ENT_CUBIC, ENT_SPHERICAL
  };
enum EMOUSE_MODE
  {
  EMM_DIRECT, EMM_PAN
  };

const c8* const NodeTypeNames[] = { "Slide", "Panel", "Cuic", "Spherical", 0 };

class Node
  {
public:
  IrrlichtDevice *Device; //!< EternitY3D::Device is required.
  ISceneNode *Root; //!< ISceneNode pointer of this node.
  IGUIStaticText *GUIRoot; //for panels and patchpanels
  IGUIImage *PanelGUI;
  ICameraSceneNode *Pointer; //for sounds and hotspots
  s32 Id; //!< Node id.
  ENODE_TYPE Type; //!< Node type: Slide, Panel, SkyBox or SkyDome.
  int DefaultCursor; //!< default cursor icon.
  EMOUSE_MODE MouseMode; //!< default mouse mode.

  AudioDevicePtr AudioDev;

  //CUBIC
  ITexture *Texture[6];
  stringc Sides[6];
  //SPHERICAL
  stringc Equirect;
  //CUBIC+SPHERICAL
  vector3df Rotation;
  //PANEL
  position2d<s32> Position;
  SColor Color;
  //PANEL+SLIDE
  stringc Background;

  std::vector<Patch *> Patches;
  std::vector<Sound *> Sounds;
  std::vector<Sensor *> Sensors;

  /*!
   \param device EternitY3D::Device.
   \param id autoassigned by the engine.
   \param type ENODE_TYPE {ENT_SLIDE, ENT_PANEL, ENT_CUBIC, ENT_SPHERICAL}
   */
  Node(IrrlichtDevice *device, s32 id, ENODE_TYPE type);
  virtual ~Node();

  void getRoot(); //!< return a pointer to the parent ISceneNode of the node in order to add childs. \return pointer to the root of the node.
  s32 getId(); //!< get the id number of the node. \return Node::Id.
  void setId(s32 newId); //!< set the node id dor internal use. \param newId set the node id manually.
  ENODE_TYPE getType(); //!< return what kind of node is it. \return ENODE_TYPE.
  void setDefaultCursor(ECURSOR_ICON cursor); //!< set what cursor is shown when no controls are touched.
  void setMouseMode(EMOUSE_MODE mouseMode);

  //EVENTS
  void onEnter();
  void onLeave();

  //SKYBOX
  void addPatch(stringc image, bool visible, f32 x, f32 y, f32 w, f32 h, int face, SColor color = SColor(255,255,255,255));

  //SKYDOME
  void addPatch(stringc image, bool visible, f32 azimuth, f32 elevation, f32 w, f32 h, SColor color);
  //PANEL
  void addPatch(stringc image, s32 x, s32 y, s32 w, s32 h, SColor color, bool visible);

  Patch *getPatch(int index);

  //SOUND
  void addSound(stringc source, bool autostart = false, bool repeat = false,
                float volume = 1.0, float pan = 0.0, float pitch = 1.0, f32 az = 0.0,
                f32 el = 0.0);
  Sound *getSound(int index);

  //SENSOR
  void addSensor(f32 width, f32 height, f32 az, f32 el,
s32 target, int effect, float factor,int duration, int cursor, std::string message, bool enable = true);
  void addSensor(s32 width, s32 height, s32 x, s32 y,
s32 target, int effect, float factor,int duration, int cursor, std::string message, bool enable = true);
  Sensor *getSensor(int index);

  //SERIALIZE
  void serialize(IAttributes* attributes);


protected:
private:
  };

#endif // _NODE_H_
